<template>
  <!-- 注册页 -->
  <div id="app">
    <div class="container">
      <div class="close">
        <span class="iconfont iconicon-test"> </span>
      </div>
      <div class="logo">
        <span class="iconfont iconnew"> </span>
      </div>
      <div class="inputs">
        <div class="input">
          <hminput
            placeholder="用户名/手机号"
            v-model="user.username"
            :rules="/^1\d{10}$|^1\d{4}$/"
            type="text"
          ></hminput>
          <hminput
            placeholder="昵称"
            v-model="user.nickname"
            type="text"
          ></hminput>
          <hminput
            placeholder="密码"
            v-model="user.password"
            type="password"
          ></hminput>
        </div>
      </div>
      <p class="tips">
        已有账号？
        <a href="/login" class="">去登录</a>
      </p>
      <hmbutton type="green" @click="register">
        <span>注册</span>
      </hmbutton>
    </div>
  </div>
</template>

<script>
import hmbutton from "@/components/hmbutton.vue";
import hminput from "@/components/hminput.vue";
import { myregister } from "@/apis/user.js";
export default {
  data() {
    return {
      user: {
        username: "",
        password: "",
        nickname: "",
      },
    };
  },
  methods: {
    async register(e) {
      try {
        let res = await myregister(this.user);

        // console.log(res);
        if (res.data.message == "注册成功") {
          this.$toast.success(res.data.message);

          this.$router.push({ name: "login" });
        } else {
          this.$toast.fail("注册失败");
        }
      } catch (e) {
        this.$toast.fail("注册失败");
      }
    },
  },
  components: {
    hmbutton,
    hminput,
  },
};
</script>

<style lang="less" scoped>
.container {
  padding: 20px;
}

.close {
  span {
    font-size: 27 / 360 * 100vw;
  }
}

.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: 126 / 360 * 100vw;
    color: #d81e06;
  }
}

.inputs {
  input {
    margin-bottom: 20px;
    padding: 0;
  }
}

.tips {
  text-align: right;
  margin-bottom: 20px;

  a {
    color: #3385ff;
  }
}
.container {
  background-color: #eaeaea;
  height: 100vh;
}
</style>